from src.common.logger import getLogger

logger = getLogger()

def load_setting_list(args):
    from ..model.SystemSetting import SystemSetting
    source = args.get("source")
    name = args.get("name")

    query = SystemSetting.query
    if source:
        query = query.filter(SystemSetting.source == source)
    if name:
        query = query.filter(SystemSetting.name == name)

    list = []
    settings = query.all()
    for record in settings:
        item = record.to_dict()
        if item["create_time"]:
            item["create_time"] = item["create_time"].strftime('%Y-%m-%d %H:%M:%S')
        list.append(item)
    return list

def save_setting_item(system_setting):
    from ... import db
    db.session.add(system_setting)
    db.session.commit()
